package com.gitee.huanminabc.fastboot.load.hook;

import com.gitee.huanminabc.fastboot.common.Order;
import com.gitee.huanminabc.fastboot.context.AppContextUtil;

/**
 * 生命周期钩子
 *
 * @Author: huanmin
 * @Date: 2025/4/3 02:27
 * @Version: 1.0
 * @Description: 文件作用详细描述....
 */
public interface LifecycleHook extends Order {
    void run();

    //项目生命周期添加
    static void addLifecycleHook(LifecycleHook hook) {
        if (hook instanceof ProjectClassLoadFinishHook) {
            ProjectClassLoadFinishLifecycleHook.projectClassLoadFinishHooks.add((ProjectClassLoadFinishHook) hook);
            return;
        }
        if (hook instanceof ClassLoadContainerFinishHook) {
            ClassLoadContainerFinishLifecycleHook.classLoadContainerFinishHooks.add((ClassLoadContainerFinishHook) hook);
            return;
        }
        if (hook instanceof LoadAppConfigFinishHook) {
            LoadAppConfigFinishLifecycleHook.loadAppConfigFinishHooks.add((LoadAppConfigFinishHook) hook);
            return;
        }

        if (hook instanceof AppLoadFinishHook) {
            AppLoadFinishLifecycleHook.appLoadFinishHooks.add((AppLoadFinishHook) hook);
            return;
        }
        if (hook instanceof ConfigValueInjectionFinishHook) {
            ConfigValueInjectionFinishLifecycleHook.configValueInjectionFinishHooks.add((ConfigValueInjectionFinishHook) hook);
            return;
        }
        if (hook instanceof DependencyInjectionFinishHook) {
            DependencyInjectionFinishLifecycleHook.dependencyInjectionFinishHooks.add((DependencyInjectionFinishHook) hook);
            return;
        }
        if (hook instanceof AppStopHook) {
            AppStopHookLifecycleHook.appStopHooks.add((AppStopHook) hook);
            return;
        }
        if (hook instanceof AppStartHook) {
            AppStartHookLifecycleHook.appStartHooks.add((AppStartHook) hook);
            return;
        }
        if (hook instanceof ContainerInitCallBackHook) {
            ContainerInitCallBackFinishLifecycleHook.configValueInjectionFinishHooks.add((ContainerInitCallBackHook) hook);
            return;
        }
        throw new IllegalArgumentException("Unknown hook: " + hook);
    }
}
